<?php
function getwarn($class)
{
    global $psql, $tb_warn, $gid, $userid;
    $psql->query("select je,ks from `$tb_warn` where userid='$userid' and gid='$gid' and class='$class'");
    $psql->next_record();
    return array(
        "je" => $psql->f('je'),
        "ks" => $psql->f('ks')
    );
}
function getgame()
{
    global $psql, $tb_game;
    $psql->query("select gid,gname,fast,panstatus,otherstatus,otherclosetime,userclosetime,mnum,fenlei,ifopen,autokj from `$tb_game` order by xsort");
    $i = 0;
    while ($psql->next_record()) {
        $game[$i]['gid']            = $psql->f('gid');
        $game[$i]['gname']          = $psql->f('gname');
        $game[$i]['fast']           = $psql->f('fast');
        $game[$i]['mnum']           = $psql->f('mnum');
		$game[$i]['fenlei']           = $psql->f('fenlei');
		$game[$i]['xsort']           = $psql->f('xsort');
        $game[$i]['panstatus']      = $psql->f('panstatus');
        $game[$i]['otherstatus']    = $psql->f('otherstatus');
        $game[$i]['otherclosetime'] = $psql->f('otherclosetime');
        $game[$i]['userclosetime']  = $psql->f('userclosetime');
		$game[$i]['ifopen']           = $psql->f('ifopen');
		$game[$i]['autokj']           = $psql->f('autokj');
        $i++;
    }
    return $game;
}
function mtype($v)
{
    global $config;
    $i = 0;
    foreach ($config['mtype'] as $n) {
        if ($n == $v) {
            break;
        }
        $i++;
    }
    return $i;
}
function ftype($v)
{
    global $config;
    foreach ($config['ftype'] as $key => $n) {
        if ($n == $v) {
            $i = $key;
            break;
        }
    }
    $i = str_replace('p', '', $key);
    return $i;
}
function dftype($v)
{
    global $config;
    foreach ($config['dftype'] as $key => $n) {
        if ($n == $v) {
            $i = $key;
            break;
        }
    }
    $i = str_replace('p', '', $key);
    return $i;
}
function ztype($v)
{
    global $config;
    $i = 0;
    foreach ($config['ztype'] as $n) {
        if ($n == $v) {
            break;
        }
        $i++;
    }
    return $i;
}
function transb($field, $bid)
{
    global $tb_bclass, $psql, $gid;
    $psql->query("select $field from `$tb_bclass` where  gid='$gid' and bid='$bid'");
    $psql->next_record();
    return $psql->f($field);
}
function transs($field, $sid)
{
    global $tb_sclass, $psql, $gid;
    $psql->query("select $field from `$tb_sclass` where gid='$gid' and  sid='$sid'");
    $psql->next_record();
    return $psql->f($field);
}
function transc($field, $cid)
{
    global $tb_class, $psql, $gid;
    $psql->query("select $field from `$tb_class` where gid='$gid' and cid='$cid'");
    $psql->next_record();
    return $psql->f($field);
}
function transp($field, $pid)
{
    global $tb_play, $psql, $gid;
    $psql->query("select $field from `$tb_play` where gid='$gid' and pid='$pid'");
    $psql->next_record();
    return $psql->f($field);
}
function transb8($field, $bid, $gid)
{
    global $tb_bclass, $psql;
    $psql->query("select $field from `$tb_bclass` where  gid='$gid' and bid='$bid'");
    $psql->next_record();
    return $psql->f($field);
}
function transs8($field, $sid, $gid)
{
    global $tb_sclass, $psql;
    $psql->query("select $field from `$tb_sclass` where gid='$gid' and  sid='$sid'");
    $psql->next_record();
    return $psql->f($field);
}
function transc8($field, $cid, $gid)
{
    global $tb_class, $psql;
    $psql->query("select $field from `$tb_class` where gid='$gid' and cid='$cid'");
    $psql->next_record();
    return $psql->f($field);
}
function transp8($field, $pid, $gid)
{
    global $tb_play, $psql;
    $psql->query("select $field from `$tb_play` where gid='$gid' and pid='$pid'");
    $psql->next_record();
    return $psql->f($field);
}
function untransp($bid, $sid, $cid, $name)
{
    global $tb_play, $psql, $gid;
    $psql->query("select pid from `$tb_play` where gid='$gid' and bid='$bid'  and sid='$sid'  and cid='$cid' and name='$name'");
    $psql->next_record();
    return $psql->f('pid');
}
function getb8h($gid)
{
    global $tsql,  $tb_bclass;

    $tsql->query("select * from `$tb_bclass` where gid='$gid' and ifok=1 order by xsort");
    $i = 0;
    $b = array();
    while ($tsql->next_record()) {
        $b[$i]['bid']  = $tsql->f('bid');
        $b[$i]['name'] = $tsql->f('name');
        $b[$i]['i']    = $i;
        $i++;
    }

    return $b;
}
function getbh()
{
    global $tsql, $gid, $tb_bclass;


    $tsql->query("select * from `$tb_bclass` where gid='$gid' and ifok=1 order by xsort");
    $i = 0;
    $b = array();
    while ($tsql->next_record()) {
        $b[$i]['bid']  = $tsql->f('bid');
        $b[$i]['name'] = $tsql->f('name');
        $b[$i]['i']    = $i;
        $i++;
    }
    return $b;
}
function getb8($gid)
{
    global $tsql,  $tb_bclass;
	$fenlei = transgame($gid,'fenlei');
	if($fenlei==107){
      $b[0]['bid'] = 0;
	  $b[0]['i'] = 0;
	  $b[0]['name'] = '冠、亚军组合';
      $b[1]['bid'] = 1;
	  $b[1]['i'] = 1;
	  $b[1]['name'] = '三、四、五、六名';
      $b[2]['bid'] = 2;
	  $b[2]['i'] = 2;
	  $b[2]['name'] = '七、八、九、十名';
	}else{
    $tsql->query("select * from `$tb_bclass` where gid='$gid' and ifok=1 order by xsort");
    $i = 0;
    $b = array();
    while ($tsql->next_record()) {
        $b[$i]['bid']  = $tsql->f('bid');
        $b[$i]['name'] = $tsql->f('name');
        $b[$i]['i']    = $i;
        $i++;
    }
	}
    return $b;
}
function getb()
{
    global $tsql, $gid, $tb_bclass;
	if($gid==107){
      $b[0]['bid'] = 0;
	  $b[0]['i'] = 0;
	  $b[0]['name'] = '冠、亚军组合';
      $b[1]['bid'] = 1;
	  $b[1]['i'] = 1;
	  $b[1]['name'] = '三、四、五、六名';
      $b[2]['bid'] = 2;
	  $b[2]['i'] = 2;
	  $b[2]['name'] = '七、八、九、十名';
	}else{

    $tsql->query("select * from `$tb_bclass` where gid='$gid' and ifok=1 order by xsort");
    $i = 0;
    $b = array();
    while ($tsql->next_record()) {
        $b[$i]['bid']  = $tsql->f('bid');
        $b[$i]['name'] = $tsql->f('name');
        $b[$i]['i']    = $i;
        $i++;
    }}
    return $b;
}
function gets($bid = '')
{
    global $tsql, $gid, $tb_sclass, $tb_bclass;
    if ($bid != '') {
        $tsql->query("select * from `$tb_sclass` where gid='$gid' and bid='$bid' and ifok=1 order by xsort");
    } else {
        $tsql->query("select * from `$tb_sclass` where gid='$gid'  and ifok=1 order by xsort");
    }//and bid=(select bid from `$tb_bclass` where gid='$gid' order by xsort limit 1)
    $i = 0;
    $s = array();
    while ($tsql->next_record()) {
        $s[$i]['sid']  = $tsql->f('sid');
        $s[$i]['name'] = $tsql->f('name');
        $s[$i]['i']    = $i;
        $i++;
    }
    return $s;
}
function getc($bid = '', $sid = '')
{
    global $tsql, $gid, $tb_class, $tb_bclass;
    if ($bid != '') {
        $tsql->query("select * from `$tb_class` where gid='$gid' and bid='$bid' and sid='$sid' and ifok=1 order by xsort");
    } else {
        $tsql->query("select * from `$tb_class` where gid='$gid' and bid=(select bid from `$tb_bclass` order by xsort limit 1) and ifok=1 order by xsort");
    }
    $i = 0;
    $c = array();
    while ($tsql->next_record()) {
        $c[$i]['sid']  = $tsql->f('sid');
        $c[$i]['name'] = $tsql->f('name');
        $c[$i]['i']    = $i;
        $i++;
    }
    return $c;
}
function getp107($bid, $ab, $abcd, $cid)
{
    global $tsql, $psql, $tb_play, $tb_bclass, $tb_sclass, $tb_class, $config, $userid, $tb_play_user, $gid;
    //$abcd = low($abcd);
    $time = time();
	if($bid==0){
	   $sql = "select * from `$tb_play` where gid='$gid' and bid<=23378805 order by bid desc,xsort";
	}else if($bid==1){
	   $sql = "select * from `$tb_play` where gid='$gid' and bid>=23378807 and bid<=23378813 order by bid,sid,xsort";
	}else if($bid==2){
	   $sql = "select * from `$tb_play` where gid='$gid' and bid>=23378816 and bid<=23378823 order by bid,sid,xsort";
	}
    $tsql->query($sql);
    $i    = 0;
    $p    = array();
    $cid  = 0;
    $sid  = 0;
    $csid = 1;
    $ccid = 1;
    $abcd = strtolower($abcd);
    while ($tsql->next_record()) {
        if ($sid != $tsql->f('sid') & $sid != 0)
            $csid++;
        if ($cid != $tsql->f('cid') & $cid != 0)
            $ccid++;
		if ($cid != $tsql->f('cid')){	
		   $psql->query("select dftype,ftype,name from `$tb_class` where gid='$gid' and cid='".$tsql->f('cid')."'");
		   $psql->next_record();
           $ftype           = $psql->f('ftype');
		   $dftype           = $psql->f('dftype');
		   $cname = $psql->f('name');
		}
		if ($sid != $tsql->f('sid')){
		   $sname = transs('name', $tsql->f('sid'));
		}
        $p[$i]['ftype']  = $ftype;
		$p[$i]['dftype']  = $dftype;
        $p[$i]['bid']    = $tsql->f('bid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['sname']  = $sname;
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['cname']  = $cname;
        $p[$i]['pid']    = $tsql->f('pid');
        $p[$i]['name']   = $tsql->f('name');
        $p[$i]['ifok']   = $tsql->f('ifok');
        $p[$i]['xsort']  = $tsql->f('xsort');
		$p[$i]['znum1']    = $tsql->f('znum1');
        $p[$i]['peilv1'] = (float) ($tsql->f('peilv1') - $config['patt'][$ftype][$abcd]);

        if ($config['pan'][$ftype]['ab'] == 1 & ($ab == 'B' | $ab == 'b')) {
            $p[$i]['peilv1'] += $config['patt'][$ftype]['ab'];
        }
        $p[$i]['peilv2'] = (float) $tsql->f('peilv2');
        $p[$i]['mp1']    = (float) $tsql->f('mp1');
        $p[$i]['mp2']    = (float) $tsql->f('mp2');
        $cid             = $tsql->f('cid');
        $sid             = $tsql->f('sid');
        $bid             = $tsql->f('bid');
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['bid']    = $tsql->f('bid');
        $i++;
    }
    $p[0]['csid'] = $csid;
    $p[0]['ccid'] = $ccid;
    return $p;
}
function getpsm($bid, $ab, $abcd, $cid)
{
    global $tsql, $psql, $tb_play, $tb_bclass, $tb_sclass, $tb_class, $config, $userid, $tb_play_user, $gid;
    //$abcd = low($abcd);
    $time = time();
    $tsql->query("select * from `$tb_play` where gid='$gid' and bid='$bid' order by bid,sid,xsort");
    $i    = 0;
    $p    = array();
    $cid  = 0;
    $sid  = 0;
    $csid = 1;
    $ccid = 1;
    $abcd = strtolower($abcd);
    while ($tsql->next_record()) {
        if ($sid != $tsql->f('sid') & $sid != 0)
            $csid++;
        if ($cid != $tsql->f('cid') & $cid != 0)
            $ccid++;
		if ($cid != $tsql->f('cid')){	
		   $psql->query("select dftype,ftype,name from `$tb_class` where gid='$gid' and cid='".$tsql->f('cid')."'");
		   $psql->next_record();
           $ftype           = $psql->f('ftype');
		   $dftype           = $psql->f('dftype');
		   $cname = $psql->f('name');
		}
		if ($sid != $tsql->f('sid')){
		   $sname = transs('name', $tsql->f('sid'));
		}
        $p[$i]['ftype']  = $ftype;
		$p[$i]['dftype']  = $dftype;
        $p[$i]['bid']    = $tsql->f('bid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['sname']  = $sname;
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['cname']  = $cname;
        $p[$i]['pid']    = $tsql->f('pid');
        $p[$i]['name']   = $tsql->f('name');
        $p[$i]['ifok']   = $tsql->f('ifok');
        $p[$i]['xsort']  = $tsql->f('xsort');
		$p[$i]['znum1']    = $tsql->f('znum1');
        $p[$i]['peilv1'] = (float) ($tsql->f('peilv1') - $config['patt'][$ftype][$abcd]);

        if ($config['pan'][$ftype]['ab'] == 1 & ($ab == 'B' | $ab == 'b')) {
            $p[$i]['peilv1'] += $config['patt'][$ftype]['ab'];
        }
        $p[$i]['peilv2'] = (float) $tsql->f('peilv2');
        $p[$i]['mp1']    = (float) $tsql->f('mp1');
        $p[$i]['mp2']    = (float) $tsql->f('mp2');
        $cid             = $tsql->f('cid');
        $sid             = $tsql->f('sid');
        $bid             = $tsql->f('bid');
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['bid']    = $tsql->f('bid');
        $i++;
    }
    $p[0]['csid'] = $csid;
    $p[0]['ccid'] = $ccid;
    return $p;
}
function getp_1dw($bid, $ab, $abcd, $cid)
{
    global $tsql, $psql, $tb_play, $tb_bclass, $tb_sclass, $tb_class, $config, $userid, $tb_play_user, $gid;
    //$abcd = low($abcd);
    $time = time();
    $tsql->query("select * from `$tb_play` where gid='$gid' and bid='$bid' and name+1>0 order by bid,sid,xsort");
    $i    = 0;
    $p    = array();
    $cid  = 0;
    $sid  = 0;
    $csid = 1;
    $ccid = 1;
    $abcd = strtolower($abcd);
    while ($tsql->next_record()) {
        if ($sid != $tsql->f('sid') & $sid != 0)
            $csid++;
        if ($cid != $tsql->f('cid') & $cid != 0)
            $ccid++;
		if ($cid != $tsql->f('cid')){	
		   $psql->query("select dftype,ftype,name from `$tb_class` where gid='$gid' and cid='".$tsql->f('cid')."'");
		   $psql->next_record();
           $ftype           = $psql->f('ftype');
		   $dftype           = $psql->f('dftype');
		   $cname = $psql->f('name');
		}
		if ($sid != $tsql->f('sid')){
		   $sname = transs('name', $tsql->f('sid'));
		}
        $p[$i]['ftype']  = $ftype;
		$p[$i]['dftype']  = $dftype;
        $p[$i]['bid']    = $tsql->f('bid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['sname']  = $sname;
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['cname']  = $cname;
        $p[$i]['pid']    = $tsql->f('pid');
        $p[$i]['name']   = $tsql->f('name');
        $p[$i]['ifok']   = $tsql->f('ifok');
        $p[$i]['xsort']  = $tsql->f('xsort');
        $p[$i]['peilv1'] = (float) ($tsql->f('peilv1') - $config['patt'][$ftype][$abcd]);

        if ($config['pan'][$ftype]['ab'] == 1 & ($ab == 'B' | $ab == 'b')) {
            $p[$i]['peilv1'] += $config['patt'][$ftype]['ab'];
        }
        $p[$i]['peilv2'] = (float) $tsql->f('peilv2');
        $p[$i]['mp1']    = (float) $tsql->f('mp1');
        $p[$i]['mp2']    = (float) $tsql->f('mp2');
        $cid             = $tsql->f('cid');
        $sid             = $tsql->f('sid');
        $bid             = $tsql->f('bid');
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['bid']    = $tsql->f('bid');
        $i++;
    }
    $p[0]['csid'] = $csid;
    $p[0]['ccid'] = $ccid;
    return $p;
}
function getpsmc($bid, $ab, $abcd, $cid, $p)
{
    global $tsql, $psql, $tb_play, $tb_bclass, $tb_sclass, $tb_class, $config, $userid, $tb_play_user, $gid;
    //$abcd = low($abcd);
    $time = time();
    if (!is_numeric($p) | $p < 0 | $p > 10)
        $p = 0;
    $tsql->query("select count(id) from `$tb_play` where gid='$gid' and bid='$bid' and cid='$cid' and ifok=1");
    $tsql->next_record();
    $rcount = $tsql->f(0);
    if ($rcount < 200) {
        $tsql->query("select * from `$tb_play` where gid='$gid' and bid='$bid' and cid='$cid'  order by bid,sid,cid,xsort");
    } else {
        $tsql->query("select * from `$tb_play` where gid='$gid' and bid='$bid' and cid='$cid'  order by bid,sid,cid,xsort limit " . ($p * 100) . ",100");
    }
    $i    = 0;
    $p    = array();
    $cid  = 0;
    $sid  = 0;
    $csid = 0;
    $ccid = 0;
    $abcd = strtolower($abcd);
    while ($tsql->next_record()) {
        if ($sid != $tsql->f('sid') & $sid != 0)
            $csid++;
        if ($cid != $tsql->f('cid') & $cid != 0)
            $ccid++;
		if ($cid != $tsql->f('cid')){	
		   $psql->query("select dftype,ftype,name from `$tb_class` where gid='$gid' and cid='".$tsql->f('cid')."'");
		   $psql->next_record();
           $ftype           = $psql->f('ftype');
		   $dftype           = $psql->f('dftype');
		   $cname = $psql->f('name');
		}
		if ($sid != $tsql->f('sid')){
		   $sname = transs('name', $tsql->f('sid'));
		}
        $p[$i]['ftype']  = $ftype;
		$p[$i]['dftype']  = $dftype;
        $p[$i]['bid']    = $tsql->f('bid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['sname']  = $sname;
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['cname']  = $cname;
        $p[$i]['pid']   = $tsql->f('pid');
        $p[$i]['ifok']  = $tsql->f('ifok');
        $p[$i]['name']  = $tsql->f('name');
        $p[$i]['xsort'] = $tsql->f('xsort');
        if ($abcd == 'a') {
            $p[$i]['peilv1'] = (float) $tsql->f('peilv1');
        } else {
            $p[$i]['peilv1'] = (float) ($tsql->f('peilv1') - $tsql->f($abcd));
        }
        $p[$i]['b'] = $tsql->f('b');
        $p[$i]['c'] = $tsql->f('c');
        $p[$i]['d'] = $tsql->f('d');
        if ($config['pan'][$ftype]['ab'] == 1 & ($ab == 'B' | $ab == 'b')) {
            $p[$i]['peilv1'] += $config['patt'][$ftype]['ab'];
        }
        $p[$i]['peilv2'] = (float) $tsql->f('peilv2');
        $p[$i]['ztype']  = $tsql->f('ztype');
        $p[$i]['mp1']    = (float) $tsql->f('mp1');
        $p[$i]['mp2']    = $tsql->f('mp2');
        $cid             = $tsql->f('cid');
        $sid             = $tsql->f('sid');
        $bid             = $tsql->f('bid');
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['bid']    = $tsql->f('bid');
        $i++;
    }
    $p[0]['csid'] = $csid;
    $p[0]['ccid'] = $ccid;
    return $p;
}
function getpsmd($bid, $ab, $abcd, $cid, $sid)
{
    global $tsql, $psql, $tb_play, $tb_bclass, $tb_sclass, $tb_class, $config, $userid, $tb_play_user, $gid;
    //$abcd = low($abcd);
    $time = time();
    if ($sid != '') {
        $tsql->query("select * from `$tb_play` where gid='$gid' and bid='$bid'  and sid='$sid' and ifok=1 order by bid,xsort");
    } else {
        $tsql->query("select * from `$tb_play` where gid='$gid' and bid='$bid'  and ifok=1  order by sid,xsort");
    }
    $i    = 0;
    $p    = array();
    $cid  = 0;
    $sid  = 0;
    $csid = 1;
    $ccid = 1;
    $abcd = strtolower($abcd);
    while ($tsql->next_record()) {
        if ($sid != $tsql->f('sid') & $sid != 0)
            $csid++;
        if ($cid != $tsql->f('cid') & $cid != 0)
            $ccid++;
		if ($cid != $tsql->f('cid')){	
		   $psql->query("select dftype,ftype,name from `$tb_class` where gid='$gid' and cid='".$tsql->f('cid')."'");
		   $psql->next_record();
           $ftype           = $psql->f('ftype');
		   $dftype           = $psql->f('dftype');
		   $cname = $psql->f('name');
		}
		if ($sid != $tsql->f('sid')){
		   $sname = transs('name', $tsql->f('sid'));
		}
        $p[$i]['ftype']  = $ftype;
		$p[$i]['dftype']  = $dftype;
        $p[$i]['bid']    = $tsql->f('bid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['sname']  = $sname;
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['cname']  = $cname;
        $p[$i]['pid']    = $tsql->f('pid');
        $p[$i]['ifok']   = $tsql->f('ifok');
        $p[$i]['name']   = $tsql->f('name');
        $p[$i]['xsort']  = $tsql->f('xsort');
        $p[$i]['peilv1'] = (float) ($tsql->f('peilv1') - $config['patt'][$ftype][$abcd]);

        if ($config['pan'][$ftype]['ab'] == 1 & ($ab == 'B' | $ab == 'b')) {
            $p[$i]['peilv1'] += $config['patt'][$ftype]['ab'];
        }
        $p[$i]['peilv2'] = (float) $tsql->f('peilv2');
        $p[$i]['mp1']    = (float) $tsql->f('mp1');
        $p[$i]['mp2']    = $tsql->f('mp2');
        $cid             = $tsql->f('cid');
        $sid             = $tsql->f('sid');
        $bid             = $tsql->f('bid');
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['bid']    = $tsql->f('bid');
        $i++;
    }
    $p[0]['csid'] = $csid;
    $p[0]['ccid'] = $ccid;
    return $p;
}
function getpsmq($bid, $ab, $abcd, $cid)
{
    global $tsql, $psql, $tb_play, $tb_bclass, $tb_sclass, $tb_class, $config, $userid, $tb_play_user, $gid;
    //$abcd = low($abcd);
    $time = time();
    $tsql->query("select * from `$tb_play` where gid='$gid' and bid='$bid'  order by bid,sid,cid,xsort");
    $i    = 0;
    $p    = array();
    $cid  = 0;
    $sid  = 0;
    $csid = 1;
    $ccid = 1;
    $abcd = strtolower($abcd);
    while ($tsql->next_record()) {
        if ($sid != $tsql->f('sid') & $sid != 0)
            $csid++;
        if ($cid != $tsql->f('cid') & $cid != 0)
            $ccid++;
		if ($cid != $tsql->f('cid')){	
		   $psql->query("select dftype,ftype,name from `$tb_class` where gid='$gid' and cid='".$tsql->f('cid')."'");
		   $psql->next_record();
           $ftype           = $psql->f('ftype');
		   $dftype           = $psql->f('dftype');
		   $cname = $psql->f('name');
		}
		if ($sid != $tsql->f('sid')){
		   $sname = transs('name', $tsql->f('sid'));
		}
        $p[$i]['ftype']  = $ftype;
		$p[$i]['dftype']  = $dftype;
        $p[$i]['bid']    = $tsql->f('bid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['sname']  = $sname;
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['cname']  = $cname;
        $p[$i]['pid']    = $tsql->f('pid');
        $p[$i]['ifok']   = $tsql->f('ifok');
        $p[$i]['name']   = $tsql->f('name');
        $p[$i]['xsort']  = $tsql->f('xsort');
        $p[$i]['peilv1'] = (float) ($tsql->f('peilv1') - $config['patt'][$ftype][$abcd]);

        if ($config['pan'][$ftype]['ab'] == 1 & ($ab == 'B' | $ab == 'b')) {
            $p[$i]['peilv1'] += $config['patt'][$ftype]['ab'];
        }
        $p[$i]['peilv2'] = (float) $tsql->f('peilv2');
        $p[$i]['mp1']    = (float) $tsql->f('mp1');
        $p[$i]['mp2']    = $tsql->f('mp2');
        $cid             = $tsql->f('cid');
        $sid             = $tsql->f('sid');
        $bid             = $tsql->f('bid');
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['bid']    = $tsql->f('bid');
        $i++;
    }
    $p[0]['csid'] = $csid;
    $p[0]['ccid'] = $ccid;
    return $p;
}
function getpsme($bid, $ab, $abcd, $sid)
{
    global $tsql, $psql, $tb_play, $tb_bclass, $tb_sclass, $tb_class, $config, $userid, $tb_play_user, $gid;
    $abcd = low($abcd);
    $time = time();
	if($bid==''){
	   $tsql->query("select * from `$tb_play` where gid='$gid' and sid='$sid' order by bid,sid,xsort");
	}else if($sid==''){
	   $tsql->query("select * from `$tb_play` where gid='$gid' and bid='$bid'  order by bid,sid,xsort");
	   
	}else{
	   $tsql->query("select * from `$tb_play` where gid='$gid' and bid='$bid' and sid='$sid' order by bid,sid,xsort");
	}
    $i    = 0;
    $p    = array();
    $cid  = 0;
    $sid  = 0;
    $csid = 1;
    $ccid = 1;
    $abcd = strtolower($abcd);
    while ($tsql->next_record()) {
        if ($sid != $tsql->f('sid') & $sid != 0)
            $csid++;
        if ($cid != $tsql->f('cid') & $cid != 0)
            $ccid++;
		if ($cid != $tsql->f('cid')){	
		   $psql->query("select dftype,ftype,name from `$tb_class` where gid='$gid' and cid='".$tsql->f('cid')."'");
		   $psql->next_record();
           $ftype           = $psql->f('ftype');
		   $dftype           = $psql->f('dftype');
		   $cname = $psql->f('name');
		}
		if ($sid != $tsql->f('sid')){
		   $sname = transs('name', $tsql->f('sid'));
		}
        $p[$i]['ftype']  = $ftype;
		$p[$i]['dftype']  = $dftype;
        $p[$i]['bid']    = $tsql->f('bid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['sname']  = $sname;
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['cname']  = $cname;
        $p[$i]['pid']    = $tsql->f('pid');
        $p[$i]['ifok']   = $tsql->f('ifok');
        $p[$i]['name']   = $tsql->f('name');
        $p[$i]['xsort']  = $tsql->f('xsort');
        $p[$i]['peilv1'] = (float) ($tsql->f('peilv1') - $config['patt'][$ftype][$abcd]);

        if ($config['pan'][$ftype]['ab'] == 1 & ($ab == 'B' | $ab == 'b')) {
            $p[$i]['peilv1'] += $config['patt'][$ftype]['ab'];
        }
        $p[$i]['peilv2'] = (float) $tsql->f('peilv2');
        $p[$i]['mp1']    = (float) $tsql->f('mp1');
        $p[$i]['mp2']    = $tsql->f('mp2');
		$p[$i]['znum1']    = $tsql->f('znum1');
		//$p[$i]['znum2']    = $tsql->f('znum2');
        $cid             = $tsql->f('cid');
        $sid             = $tsql->f('sid');
        $bid             = $tsql->f('bid');
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['bid']    = $tsql->f('bid');
        $i++;
    }
    $p[0]['csid'] = $csid;
    $p[0]['ccid'] = $ccid;
    return $p;
}
function getpsm60($bid, $ab, $abcd, $sid)
{
    global $tsql, $psql, $tb_play, $tb_bclass, $tb_sclass, $tb_class, $config, $userid, $tb_play_user, $gid;
    $abcd = low($abcd);
    $time = time();
    $tsql->query("select * from `$tb_play` where gid='$gid'  and sid='$sid' order by bid,xsort");
    $i    = 0;
    $p    = array();
    $cid  = 0;
    $sid  = 0;
    $csid = 1;
    $ccid = 1;
    $abcd = strtolower($abcd);
    while ($tsql->next_record()) {
        if ($sid != $tsql->f('sid') & $sid != 0)
            $csid++;
        if ($cid != $tsql->f('cid') & $cid != 0)
            $ccid++;
		if ($cid != $tsql->f('cid')){	
		   $psql->query("select dftype,ftype,name from `$tb_class` where gid='$gid' and cid='".$tsql->f('cid')."'");
		   $psql->next_record();
           $ftype           = $psql->f('ftype');
		   $dftype           = $psql->f('dftype');
		   $cname = $psql->f('name');
		}
		if ($sid != $tsql->f('sid')){
		   $sname = transs('name', $tsql->f('sid'));
		}
        $p[$i]['ftype']  = $ftype;
		$p[$i]['dftype']  = $dftype;
        $p[$i]['bid']    = $tsql->f('bid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['sname']  = $sname;
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['cname']  = $cname;
        $p[$i]['pid']    = $tsql->f('pid');
        $p[$i]['ifok']   = $tsql->f('ifok');
        $p[$i]['name']   = $tsql->f('name');
        $p[$i]['xsort']  = $tsql->f('xsort');
        $p[$i]['peilv1'] = (float) ($tsql->f('peilv1') - $config['patt'][$ftype][$abcd]);

        if ($config['pan'][$ftype]['ab'] == 1 & ($ab == 'B' | $ab == 'b')) {
            $p[$i]['peilv1'] += $config['patt'][$ftype]['ab'];
        }
        $p[$i]['peilv2'] = (float) $tsql->f('peilv2');
        $p[$i]['mp1']    = (float) $tsql->f('mp1');
        $p[$i]['mp2']    = $tsql->f('mp2');
        $cid             = $tsql->f('cid');
        $sid             = $tsql->f('sid');
        $bid             = $tsql->f('bid');
        $p[$i]['cid']    = $tsql->f('cid');
        $p[$i]['sid']    = $tsql->f('sid');
        $p[$i]['bid']    = $tsql->f('bid');
        $i++;
    }
    $p[0]['csid'] = $csid;
    $p[0]['ccid'] = $ccid;
    return $p;
}
function ftypes($ftype){
	$arr = array();
	foreach($ftype as $k => $v){
	    $arr[$k] = $v['name'];
	}
	return $arr;
}
function getuserpeilvcha($uid, $class)
{
    global $tb_user, $tb_zpan, $psql, $gid;
    $peilv = 0;
    while ($uid != 99999999) {
        $psql->query("select peilvcha from `$tb_zpan` where gid='$gid' and userid='$uid' and class='$class' ");
        $psql->next_record();
        $peilv += $psql->f('peilvcha');
        $psql->query("select fid from `$tb_user` where userid='$uid'");
        $psql->next_record();
        $uid = $psql->f('fid');
        if ($uid == 99999999)
            break;
    }
    return $peilv;
}
function getuserpeilvcha2($uid, $class)
{
    global $tb_user, $tb_zpan, $psql, $gid;
    $peilv = 0;
	$layer = transuser($uid,'layer');
    while ($layer>1) {
        $psql->query("select peilvcha from `$tb_zpan` where gid='$gid' and userid='$uid' and class='$class' ");
        $psql->next_record();
        $peilv += $psql->f('peilvcha');
        $psql->query("select fid,layer from `$tb_user` where userid='$uid'");
        $psql->next_record();
        $uid = $psql->f('fid');
		$layer = $psql->f('layer');
        if ($layer==2)
            break;
    }
    return $peilv;
}
function week()
{
	global $config;
	$start = str_replace(':','',$config['editstart']);
	$zuo = 0;
	if(date("His")<$start) $zuo=1;
    $getWeekDay = date("w");
    if ($getWeekDay == 0) {
        $sdate = array(
            0 => date("Y-m-d", mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'))),
            1 => date('Y-m-d', mktime(0, 0, 0, date('n'), 1, date('Y'))),
            2 => date('Y-m-d', mktime(0, 0, 0, date('n'), date('t'), date('Y'))),
            3 => date('Y-m-01', strtotime('last month')),
            4 => date('Y-m-t', strtotime('last month')),
            5 => date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $getWeekDay + 1 - 7, date("Y"))),
            6 => date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $getWeekDay + 7 - 7, date("Y"))),
            7 => date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $getWeekDay + 1 - 7 - 7, date("Y"))),
            8 => date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $getWeekDay + 7 - 7 - 7, date("Y"))),
            9 => date("Y-m-d", mktime(0, 0, 0, date('m') - 1, date('d') - 4, date('Y'))),
            10 => date("Y-m-d")
        );

    } else {
        $sdate = array(
            0 => date("Y-m-d", mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'))),
            1 => date('Y-m-d', mktime(0, 0, 0, date('n'), 1, date('Y'))),
            2 => date('Y-m-d', mktime(0, 0, 0, date('n'), date('t'), date('Y'))),
            3 => date('Y-m-01', strtotime('last month')),
            4 => date('Y-m-t', strtotime('last month')),
            5 => date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $getWeekDay + 1, date("Y"))),
            6 => date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $getWeekDay + 7, date("Y"))),
            7 => date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $getWeekDay + 1 - 7, date("Y"))),
            8 => date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $getWeekDay + 7 - 7, date("Y"))),
            9 => date("Y-m-d", mktime(0, 0, 0, date('m') - 1, date('d') - 4, date('Y'))),
            10 => date("Y-m-d")
        );
    }
			if($zuo==1){
		  $sdate[0] = date("Y-m-d", mktime(0, 0, 0, date('m'), date('d') - 2, date('Y')));
		  $sdate[10] = date("Y-m-d",time()-86400);
		  
		}
    return $sdate;
}
function setuptid()
{
    global $tsql,$userid,$tb_lib;
    $tsql->query("select max(tid) from `$tb_lib` where userid='$userid'");
    $tsql->next_record();
    if ($tsql->f(0) == '') {
        return '20000000';
    }
    return $tsql->f(0)+rand(1,3);
}
function getma(){
   global $psql,$tb_config;
   $psql->query("select ma from `$tb_config`");
   $psql->next_record();
   $ma = json_decode($psql->f('ma'),true);
   return $ma;
}
function getduoarr($name){
		if(strpos($name,'肖')>0){
		   $pl = array("鼠","牛","虎","兔","龍","蛇","馬","羊","猴","雞","狗","豬");
		}else if(strpos($name,'尾')>0){
		   $pl = array("0尾","1尾","2尾","3尾","4尾","5尾","6尾","7尾","8尾","9尾");
		}else{
		   $pl = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49");
		}
		return $pl;
}
function getduoarrss($gid,$name){
	
    if($gid==117 | $gid==163 | $gid==116 | $gid==118 | $gid==119 | $gid==101 | $gid==111   | $gid==113  | $gid==115 | $gid==108 | $gid==109 | $gid==110 | $gid==112){	
	    if((strpos('['.$name.']','组')>0)){
            $pl = array("0","1","2","3","4","5","6","7","8","9");
		}else{	
		      $names = str_replace('定位','',$name);
			  $nl = strlen($names);	    
			if($nl==6){				
				$pl = array(substr($names,0,$nl/2)."-0","1","2","3","4","5","6","7","8","9",substr($names,$nl/2)."-0","1","2","3","4","5","6","7","8","9");
			}else{ 
			   if(strpos('['.$name.']','前三')){
			      $pl = array("万-0","1","2","3","4","5","6","7","8","9","千-0","1","2","3","4","5","6","7","8","9","百-0","1","2","3","4","5","6","7","8","9");
			   }else if(strpos('['.$name.']','中三')){
			      $pl = array("千-0","1","2","3","4","5","6","7","8","9","百-0","1","2","3","4","5","6","7","8","9","十-0","1","2","3","4","5","6","7","8","9");
			   }else{
			      $pl = array("百-0","1","2","3","4","5","6","7","8","9","十-0","1","2","3","4","5","6","7","8","9","个-0","1","2","3","4","5","6","7","8","9");
			   }
			}
		}
	}else if($gid==121 | $gid==123 | $gid==125 | $gid==127  | $gid==129){
		if($name=='选前二直选'){
			$pl = array("第1球-01","02","03","04","05","06","07","08","09","10","11","第2球-01","02","03","04","05","06","07","08","09","10","11");
		}else if($name=='选前三直选'){
			$pl = array("第1球-01","02","03","04","05","06","07","08","09","10","11","第2球-01","02","03","04","05","06","07","08","09","10","11","第3球-01","02","03","04","05","06","07","08","09","10","11");
		}else{
		$pl = array("01","02","03","04","05","06","07","08","09","10","11");
		}
	}else if($gid==103 | $gid==133 | $gid==135 | $gid==131 | $gid==132  | $gid==136){
		if($name=='选二连直'){
		    $pl = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20");
		}else if($name=='选三前直'){
		    $pl = array("第1球-01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","第2球-01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","第3球-01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20");
		}else{
		   $pl = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20");
		}
	}
	return $pl;
}
function getduoarrssuser($gid,$name){
	
    if($gid==117 | $gid==163 | $gid==116 | $gid==118 | $gid==119 | $gid==101 | $gid==111   | $gid==113  | $gid==115 | $gid==108 | $gid==109 | $gid==110 | $gid==112){	
	    if((strpos('['.$name.']','组')>0)){
            $pl = array("0","1","2","3","4","5","6","7","8","9");
		}else{	
		      $names = str_replace('定位','',$name);
			  $nl = strlen($names);	    
			if($nl==6){				
				$pl = array("0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9");
			}else{ 
			   if(strpos('['.$name.']','前三')){
			      $pl = array("0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9");
			   }else if(strpos('['.$name.']','中三')){
			      $pl = array("0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9");
			   }else{
			      $pl = array("0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9","0","1","2","3","4","5","6","7","8","9");
			   }
			}
		}
	}else if($gid==121 | $gid==123 | $gid==125 | $gid==127  | $gid==129){
		if($name=='选前二直选'){
			$pl = array("01","02","03","04","05","06","07","08","09","10","11","01","02","03","04","05","06","07","08","09","10","11");
		}else if($name=='选前三直选'){
			$pl = array("01","02","03","04","05","06","07","08","09","10","11","01","02","03","04","05","06","07","08","09","10","11","01","02","03","04","05","06","07","08","09","10","11");
		}else{
		$pl = array("01","02","03","04","05","06","07","08","09","10","11");
		}
	}else if($gid==103 | $gid==133 | $gid==135 | $gid==131 | $gid==132  | $gid==136){
		if($name=='选二连直'){
		    $pl = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20");
		}else if($name=='选三前直'){
		    $pl = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20");
		}else{
		   $pl = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20");
		}
	}
	return $pl;
}
function rduokey($arr,$v1){
   foreach($arr as $key => $v2){
       if($v2==$v1){
	       return $key;
	   }
   }
}
function rduokeydw($arr,$v1,$kk){
   foreach($arr as $key => $v2){
       if($v2==$v1){
	       return $key+$kk*10;
	   }
   }
}
function rduokeyklsf($arr,$v1,$kk){
   foreach($arr as $key => $v2){
       if($v2==$v1){
	       return $key+$kk*20;
	   }
   }
}
function rduokeysyxw($arr,$v1,$kk){
   foreach($arr as $key => $v2){
       if($v2==$v1){
	       return $key+$kk*11;
	   }
   }
}
function formatqs($gid, $qs)
{
    if ($gid == 103 | $gid == 113 | $gid == 123)
        $qs = substr($qs, 0, 8) . substr($qs, -2);
    else if ( $gid==152 | $gid==153 | $gid==155 | $gid==157)
        $qs = substr($qs, -9);
    else if ($gid == 121 | $gid == 125)
        $qs = substr($qs, 2, 6) . substr($qs, -2);
    return $qs;
}

function kjmyself($qishu,$mnum){	
    $m= array();
	if($mnum==3){
		$arr = array(0,1,2,3,4,5,6,7,8,9);
		$m[0] = $arr[rand(0,9)];
		$m[1] = $arr[rand(0,9)];
		$m[2] = $arr[rand(0,9)];
	}else if($mnum==5){
		$arr = array(0,1,2,3,4,5,6,7,8,9);
		$m[0] = $arr[rand(0,9)];
		$m[1] = $arr[rand(0,9)];
		$m[2] = $arr[rand(0,9)];
		$m[3] = $arr[rand(0,9)];
		$m[4] = $arr[rand(0,9)];
	}else if($mnum==8){
		$arr = array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20");
		 $m[0] = $arr[rand(0,19)];
		for($i=1;$i<8;$i++){
		   $m[$i] = randm($m,$arr,$mnum);
		}
	}else if($mnum==10){
		$arr = array("01","02","03","04","05","06","07","08","09","10");
		 $m[0] = $arr[rand(0,9)];
		for($i=1;$i<10;$i++){
		   $m[$i] = randm($m,$arr,$mnum);
		}
	}
	$kj = array();
	$kj[0] = array();
	$kj[0]['kjtime'] = time();
	$kj[0]['qishu'] = $qishu;
	$kj[0]['m'] = $m;
	return json_encode($kj);
}
function pkskj($gid,$qishu){
	global $tsql,$psql,$tb_lib,$tb_play,$tb_bclass;
	$sql = "select name,bid from `$tb_bclass` where gid='$gid' order by xsort";
	$bc = $tsql->arr($sql);
	$cb = count($bc);
	for($i=0;$i<$cb;$i++){
	    $tsql->query("select pid,cid,name from `$tb_play` where gid='$gid' and bid='$bid' order by xsort");
		$j=0;
		$tmp=array();
		$zje=0;
		while($tsql->next_record()){
			$tmp[$j]['pid'] = $tsql->f('pid');
			$tmp[$j]['name'] = $tsql->f('name');
		    $psql->query("select sum(je) from `$tb_lib` where gid='$gid' and bid='$bid' and pid='".$tsql->f('pid')."'");
			$psql->next_record();
			$tmp[$j]['je'] = $psql->f(0);
			if($tsql->f('name')!='龙' & $tsql->f('name')!='虎'){
				$zje += $psql->f(0);
			}
			$j++;		
		}
		$ct = count($tmp);
		if($ct==21){
		   for($j=0;$j<$ct;$j++){
		      $arr=array();
			  $je=0;
			  $zharr = array("和大","和小","和单","和双");
		      if(in_array($tmp[$j]['name'],$zharr)){	
		         switch($tmp[$j]['name']){
		            case "和大":
				        $arr = array(12,13,14,15,16,17,18,19);
			        break;
				    case "和小":
				        $arr = array(3,4,5,6,7,8,9,10,11);
				    break;
		            case "和单":
				       $arr = array(3,5,7,9,11,13,15,17,19);
			        break;
				    case "和双":
				       $arr = array(4,6,8,10,12,14,16,18);
				    break;
		         }
				 $je = $tmp[$j]['je'];
				 unset($tmp[$j]);
		      }
			  if(count($arr)>0){
				 $je = $je/count($arr);
			     for($k=0;$k<$ct;$k++){
					 if(is_numeric($tmp[$k]['name']) & in_array($tmp[$k]['name'],$arr)){
					     $tmp[$k]['je'] += $je;
					 }
				 }
			  }
		   }		   
		}else{
		   for($j=0;$j<$ct;$j++){
		      $arr=array();
			  $je=0;
			  $zharr = array("单","双","大","小","质","合");
		      if(in_array($tmp[$j]['name'],$zharr)){	
		         switch($tmp[$j]['name']){
		            case "大":
				        $arr = array(6,7,8,9,10);
			        break;
				    case "小":
				        $arr = array(1,2,3,4,5);
				    break;
		            case "单":
				       $arr = array(1,3,5,7,9);
			        break;
				    case "双":
				       $arr = array(2,4,6,8,10);
				    break;
		         }
				 $je = $tmp[$j]['je'];
				 unset($tmp[$j]);
		      }
			  if(count($arr)>0){
				 $je = $je/count($arr);
			     for($k=0;$k<$ct;$k++){
					 if(is_numeric($tmp[$k]['name']) & in_array($tmp[$k]['name'],$arr)){
					     $tmp[$k]['je'] += $je;
					 }
				 }
			  }
		   }
		}
		sort($tmp);
		foreach($tmp as $v){
		   $t[] = $v['je'];
		}
		array_multisort($t, SORT_DESC, SORT_NUMERIC,$tmp);
		$bc[$i]['p']=$tmp;
		$bc[$i]['zje'] = $zje;
		$bc[$i]['i']  = $i;
		
	}
	
}

function randm($m,$arr,$mnum){
    $a = $arr[rand(0,$mnum-1)];
	if(in_array($a,$m)) return randm($m,$arr,$mnum);
	else return $a;
}


function xy28kj($arr){
	$m=array();
	$ca = count($arr);
	$tmp=0;
            for ($i = 0; $i < $ca; $i++) {
                $tmp += $arr[$i];
                if ($i == 5) {
                    $m[]  = $tmp % 10;
                    $tmp = 0;
                }
                if ($i == 11) {
                    $m[]  = $tmp % 10;
                    $tmp = 0;
                }
                if ($i == 17) {
                    $m[]  = $tmp % 10;
                    $tmp = 0;
                }
                
            }
			return $m;
}

function bml($v){
	if(strpos($v,'子')) return "鼠";
	if(strpos($v,'丑')) return "牛";
	if(strpos($v,'寅')) return "虎";
	if(strpos($v,'卯')) return "兔";
	if(strpos($v,'辰')) return "龍";
	if(strpos($v,'巳')) return "蛇";
	if(strpos($v,'午')) return "馬";
	if(strpos($v,'未')) return "羊";
	if(strpos($v,'申')) return "猴";
	if(strpos($v,'酉')) return "雞";
	if(strpos($v,'戌')) return "狗";
	if(strpos($v,'亥')) return "豬";

}
?>